package com.example.gongj;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * 字节缓冲输入流
 */
public class BufferedInputStreamDemo {
    public static void main(String[] args) throws Exception {
        //创建FileInputStream对象，绑定要读取的数据源
        FileInputStream fs = new FileInputStream("IO流\\e.txt");
        //创建BufferedInputStream对象，构造方法中传递FileInputStream对象，提高FileInputStream对象的读取效率
        BufferedInputStream bis = new BufferedInputStream(fs);
        //存储每次读取的数据
        byte[] bytes = new byte[102];
        //记录每次读取的有效字节个数
        int len = 0;
        //使用BufferedInputStream对象中的方法read，读取文件
        while((len = bis.read(bytes)) != -1){
            System.out.println(new String(bytes,0,len));
        }
        bis.close();
        fs.close();
    }
}
